package cn.iocoder.yudao.module.scenic.controller.app.comment;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.scenic.controller.admin.comment.vo.CommentPageReqVO;
import cn.iocoder.yudao.module.scenic.controller.admin.comment.vo.CommentRespVO;
import cn.iocoder.yudao.module.scenic.controller.admin.comment.vo.CommentSaveReqVO;
import cn.iocoder.yudao.module.scenic.dal.dataobject.comment.CommentDO;
import cn.iocoder.yudao.module.scenic.service.comment.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @author chenglong.ai
 * @version 1.0
 * @package cn.iocoder.yudao.module.scenic.controller.app.comment
 * @date 2024/06/04 01:09:59
 * @description
 */
@Tag(name = "app - 实践点评论")
@RestController
@RequestMapping("/scenic/comment")
@Validated
public class AppCommentController {
    @Resource
    private CommentService commentService;

    @PostMapping("/page")
    @Operation(summary = "获得实践点评论分页")
    public CommonResult<PageResult<CommentRespVO>> getCommentPage(@RequestBody @Valid CommentPageReqVO pageReqVO) {
        pageReqVO.setIsShow(true);
        PageResult<CommentDO> pageResult = commentService.getCommentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CommentRespVO.class));
    }

    @PostMapping("/create")
    @Operation(summary = "创建实践点评论")
    public CommonResult<Long> createComment(@Valid @RequestBody CommentSaveReqVO createReqVO) {
        return success(commentService.createComment(createReqVO));
    }
}
